package com.qilin.hammer;

import java.io.*;
import java.util.*;

public class FileHelper {

	
	public FileHelper(){}
	
	public static void CreateUserFile(String filepath, int num) throws IOException{
		BufferedWriter bw = new BufferedWriter(new FileWriter(filepath));
		for(int i=0;i<num;i++){
			String linetext="u"+String.valueOf(i+1)+" 123456";
			bw.write(linetext+"\r\n");
		}
		bw.flush();
	}
	
	public static void CreateMultiTypeEventData(String filepath, int size) throws IOException{
		filepath = filepath.replaceAll("\\\\", "/");		
		//BufferedReader bf = new BufferedReader(new FileReader(filepath));
		Random r=new Random(47);
		BufferedWriter bw = new BufferedWriter(new FileWriter(filepath));
		//MultiTypeData
		boolean bools[] ={true, false};
		byte bytes[]={Byte.MAX_VALUE,Byte.MIN_VALUE};
		short shorts[]={Short.MAX_VALUE,Short.MIN_VALUE};
		int ints[]={Integer.MAX_VALUE,Integer.MIN_VALUE};
		long longs[]={Long.MAX_VALUE,Long.MIN_VALUE};
		double doubles[]={Double.MAX_VALUE, Double.MIN_VALUE};
		float floats[]={Float.MAX_VALUE,Float.MIN_VALUE};
		String str="hello world";
		Object objs[]={bools[0],bytes[0],shorts[0],ints[1],longs[0],doubles[1],floats[0],str};
		String types[] = {"first", "second", "third"};
		Date date=null;
		
		for(int i=0;i<size;i++){
			str = types[r.nextInt(types.length)];
			String linetext="MultiType;"+(i+1)+";"+str+";";
			int p=i%2;
			System.out.println(i+":"+size);
			date=new Date(r.nextLong()%System.currentTimeMillis());
			
			ShowMethods.print(date.toString());
			linetext+=bools[p]+";"+bytes[p]+";"+shorts[p]+";"+ints[p]+";"
						+longs[p]+";"+r.nextDouble()*10000+";"+r.nextFloat()*10000+";"+date+";"+date
						+";"+date+";"+str+";"+objs[r.nextInt(objs.length)];
			ShowMethods.print(linetext);
			bw.write(linetext+"\r\n");
		}
		bw.flush();
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try{
			//FileHelper.CreateMultiTypeEventData("D:\\work\\M3OProjects\\Workflow110629\\dataset.txt", 50);
			FileHelper.CreateUserFile("D:\\users.txt", 100);
		}catch (IOException e){
			e.printStackTrace();
		}
	}
}
